package com.example.demo.mapper;

import com.example.demo.entity.User;
import com.example.demo.entity.UserMsg;
import org.apache.ibatis.annotations.*;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description: 1225下午作业
 * @Param: [user]
 * @return: int
 * @Author: Zwill
 * @Date: 2019/12/25
 */
@Mapper
@Repository
public interface UserMsgMapper {

    /*添加用户*/
    @Insert("insert into usermsg(uid,uname,pwd,email,createtime)values(#{uid},#{uname},#{pwd},#{email},#{createtime})")
    int insertUserMsg(UserMsg userMsg);

    /*查询所有用户名称信息*/
    @Select("select uname from usermsg")
    List<String> findAllUserNames();

    /*查询用户对应的角色*/
    @Select("select rolename from usermsg,role,userrole where usermsg.uid=userrole.uid and role.id=userrole.roleid and usermsg.uname = #{uname}")
    List<String> findUserRoles(String uname);

    /*时间区间查询*/
    @Select("SELECT * from usermsg where createtime BETWEEN #{starttime} and #{endtime}")
    List<UserMsg> queryByTimeZone(String starttime, String endtime);

    /*姓名模糊查询*/
    @Select("select * from usermsg where uname like '%${fuzzyUname}%'")
    List<UserMsg> fuzzyQueryByName(String fuzzyUname);

    /*显示列表：人员姓名、邮箱、角色名称、创建时间*/
    @Select("select uname,email,rolename,createtime from usermsg,role,userrole where usermsg.uid=userrole.uid and role.id=userrole.roleid")
    List<UserMsg> showAllMsgs();

    /*删除用户*/
    @Delete("delete from usermsg where uid = #{uid}")
    int deleteUserMsg(int uid);

    /*修改用户信息*/
    @Update("update usermsg set uname=#{uname},pwd=#{pwd},email=#{email},createtime=#{createtime} where uid = #{uid}")
    int updateUser(UserMsg userMsg);
}
